package com.itcast.util;

import java.io.*;
import java.util.*;

public class ErrorUilts {

    public static String saveErrorMessages(Throwable throwable) {
        Writer writer = new StringWriter();
        PrintWriter pw = new PrintWriter(writer);
        throwable.printStackTrace(pw);
        Throwable cause = throwable.getCause();
        // 循环取出Cause
        int count=0;
        while (cause != null&&count<10) {
            count++;
            cause.printStackTrace(pw);
            cause = throwable.getCause();
        }

        String result = writer.toString();
        return result;
    }
}
